﻿using System;
using System.Collections.Generic;
using System.Text;
using SyncCommon;
using System.Xml.Serialization;
using System.IO;
using SyncCommon.DAL;

namespace HefaSyncTool
{
    public class SharedVal
    {
        public static SerializableDictionary<long, SDWebsite> WebSites = null;
      
        static SharedVal()
        {
            try
            {
                XmlSerializer se = new XmlSerializer(typeof(SerializableDictionary<long, SDWebsite>));
                using (FileStream f = new FileStream("SDWebsite.xml", FileMode.Open,FileAccess.Read))
                {
                    WebSites = (SerializableDictionary<long, SDWebsite>)se.Deserialize(f);
                }
                List<WebLogin> logins = WebLogin.FindAll();
                foreach (WebLogin log in logins)
                {
                    if (WebSites.ContainsKey(log.WebSiteID))
                    {
                        WebSites[log.WebSiteID].UserName = log.UserName;
                        WebSites[log.WebSiteID].Password = EncryptCenter.DESDecrypt(log.Password);
                        WebSites[log.WebSiteID].IsValid = log.IsValid ?? false;
                        WebSites[log.WebSiteID].IsStart = log.IsStart ?? false;
                    }
                }
            }
            catch(Exception exp)
            {
                LogCenter.Log(exp);
            }
        }
    }
}
